import visdom
import numpy as np

# Connect to Visdom
vis = visdom.Visdom(env='rltest')

# Assuming cl represents the load for 6 computers over n time slices
n = 10  # Assuming n is 10
cl = np.random.rand(2, 3, n)  # Random data for example

# Create time array
x = np.arange(n)
y=x
vis.line(
        X=x,
        Y=y,
        opts=dict(
            title='test',
            xlabel='时间片',
            ylabel='负载'
        ),
        win='savetest' # Each subplot is given a unique window name
    )
# vis._send({'task': 'save', 'force': True, 'file': "E:\\项目\\rf_computing\\visual\\test.html",'html':True })
import requests

# 从 Visdom 服务器获取图像数据
visdom_address = 'http://localhost:8097/'  # 你的 Visdom 服务器地址
image_id = 1  # 替换为你需要保存的图像的 ID
response = requests.get(visdom_address + '/env/main/rltest/' + str(image_id) + '/png')
print(response.content)

# 保存图像到文件
with open('visdom_image.png', 'wb') as f:
    f.write(response.content)
